using System;
using System.Collections.Generic;
using System.Text;
using Forecast.Database;

namespace Forecast.Business
{
    public class TraderOverview
    {
        #region Variables

        private int _cash;
        private int _cashInStocks;
        private int _stockValue;
        private Player _player;

        #endregion
        #region Constructors

        internal TraderOverview(int playerId, Load load)
        {
            _player = load.GetPlayer(playerId);
            _cash = _player.Cash;
            IList<Offer> allActiveOffers = load.GetAllActiveOffers();
            TradersOverview tradersOverview = new TradersOverview();
            _cashInStocks = tradersOverview.GetCashInStocks(_player, allActiveOffers);
            IList<Holding> holdings = load.GetAllHoldings();
            IList<Prediction> predictions = load.GetAllActivePredictions();
            _stockValue = tradersOverview.GetTotalValueOfStocksForPlayer(_player, predictions, holdings, allActiveOffers);
        }

        internal int GetNumStocksForSale(Prediction prediction, IList<Offer> allActiveOffersInPrediction)
        {
            int numStocksForSale = 0;
            foreach (Offer offer in allActiveOffersInPrediction)
            {
                if (_player.Id != offer.PlayerId)
                    continue;
                if (offer.IsBuy)
                    continue;
                numStocksForSale += offer.NumPredictions;
            }
            return numStocksForSale;
        }

        #endregion
        #region Properties

        public int Cash
        {
            get { return _cash; }
            set { _cash = value; }
        }

        public int CashInStocks
        {
            get { return _cashInStocks; }
            set { _cashInStocks = value; }
        }

        public int StockValue
        {
            get { return _stockValue; }
            set { _stockValue = value; }
        }

        #endregion
    }
}
